from django.http import HttpResponse
from django.shortcuts import render
from firstapp.models import People
from django.template import Context, Template
from firstapp.models import Article

# Create your views here.


def first_try(request):
    person = People(name='Chendy', job='Python Coder')
    html_string = '''
        <html>
            <head>
                <meta charset="utf-8">
                <link rel="stylesheet"
                href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.css"
                media="screen"
                title="no title">
                <title> firstapp </title>
            </head>
            <body>
                <h1 class="ui center aligned icon header">
                    <i class="hand spock icon"></i>
                    hello, {{person.name}}
                </h1>
            </body>
        </html>
    '''

    t = Template(html_string)
    c = Context({'person': person})
    web_page = t.render(c)

    return HttpResponse(web_page)


def index(request):
    print(request)
    print('==='*30)
    print(dir(request))
    print('===' * 30)
    queryset = request.GET.get('tag')
    print(queryset)
    if queryset:
        article_list = Article.objects.filter(tag=queryset)
    else:
        article_list = Article.objects.all()
    context = {'article_list': article_list}
    index_page = render(request, 'first_web_2.html', context)

    return index_page


def detail(request):
    return

